[Enhancement] Implement metrics reporting for MemTrackerManager#68170
[Enhancement] Implement metrics reporting for MemTrackerManager#68170arin-mirza wants to merge 9 commits intoStarRocks:mainfrom
MemTrackerManager#68170Conversation
|
@cursor review |
1 similar comment
|
@cursor review |
|
@alvin-celerdata @kevincai I closed the previous PR where you were reviewers, can I get a review for this one, please? :) |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7a13d9f6d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@cursor review |
|
@alvin-celerdata Can this PR be merged? Is there anything else that needs to be done? |
There was a problem hiding this comment.
Pull request overview
This PR implements metrics reporting for MemTrackerManager to expose memory pool usage statistics. Previously, there were no backend metrics for memory pools. The implementation adds four new metrics: mem_pool_mem_limit_bytes, mem_pool_mem_usage_bytes, mem_pool_mem_usage_ratio, and mem_pool_workgroup_count. The implementation follows the established locking and metrics registration patterns from WorkGroupManager to avoid deadlocks with the metrics collector.
Changes:
- Added metrics infrastructure to
MemTrackerManagerwith thread-safe registration and update mechanisms - Updated
list_mem_trackers()to exclude the default memory pool, improving consistency - Added documentation in English, Chinese, and Japanese for the new metrics
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| be/src/exec/workgroup/mem_tracker_manager.h | Added MemTrackerMetrics struct, metrics-related private methods, and mutex for thread synchronization |
| be/src/exec/workgroup/mem_tracker_manager.cpp | Implemented metrics registration, update logic, and modified list_mem_trackers() to exclude default pool |
| be/test/exec/workgroup/work_group_manager_test.cpp | Updated test expectations to reflect that default memory pool is no longer included in the list, removed unnecessary sleep |
| docs/en/administration/management/monitoring/metrics.md | Added English documentation for the four new metrics |
| docs/zh/administration/management/monitoring/metrics.md | Added Chinese documentation for the four new metrics |
| docs/ja/administration/management/monitoring/metrics.md | Added Japanese documentation for the four new metrics |
| - Unit: - | ||
| - Description: Ratio of internal table scan thread time slices used by each resource group to the total used by all resource groups. This is an average value over the time interval between two metric retrievals. | ||
|
|
||
| ### mem_pool_mem_limit_bytes |
There was a problem hiding this comment.
the actual metric name will be prefixed by starrocks_be_, so to end user it is actually starrocks_be_mem_pool_mem_limit_bytes, shall use the final name since this is the doc to end user.
There was a problem hiding this comment.
I updated the documentation to use starrocks_be_ prefix.
I think the documentation is inconsistent in this regard.
Most resource group related metrics are duplicated, a description exists with and without the starrocks_be prefix. I also checked Datadog metrics to see if they are actually reported twice, but no, they are always reported under a name with the starrocks_be prefix.
In metrics.md:
| Without Prefix | With Prefix | in Datadog |
|---|---|---|
| resource_group_mem_limit_bytes | starrocks_be_resource_group_mem_limit_bytes | with prefix |
| resource_group_mem_inuse_bytes | - | with prefix |
| resource_group_cpu_limit_ratio | starrocks_be_resource_group_cpu_limit_ratio | with prefix |
| resource_group_cpu_use_ratio | starrocks_be_resource_group_cpu_use_ratio | with prefix |
| resource_group_scan_use_ratio | - | with prefix |
| resource_group_inuse_cpu_cores | - | with prefix |
| resource_group_connector_scan_use_ratio | - | with prefix |
| - | starrocks_be_resource_group_mem_allocated_bytes | does not exist |
I believe all metrics above should only have one entry with the starrocks_be prefix.
Moreover, I could not find starrocks_be_resource_group_mem_allocated_bytes in Datadog. This metric was renamed to resource_group_mem_inuse_bytes in 6204611 on 2022-06-29. The entry should be removed from the user documentation if safe to do so.
There was a problem hiding this comment.
Yeah, I think the doc is messed up somehow, the actual metrics name produced via /metrics should be the canonical one in this doc.
Just keep the new added ones prefixed with the starrocks_be_, other inconsistent ones will be fixed in a dedicated PR.
| metrics->workgroup_count->set_value(child_count); | ||
| } | ||
| } else { | ||
| // Metrics entries for deleted shared_mem_trackers are never deleted, but simply set to 0. |
There was a problem hiding this comment.
in a long running system with Frequent workergroup creation and deletion, will thes garbage metrics accumulated and cause memory occupation and long useless serialization to the /metrics interface.
There was a problem hiding this comment.
Not really.
Workgroups by default belong to DEFAULT_MEM_POOL , these are not tracked in MemTrackerManager and it does not report mempool statistics for such work groups. Frequent creation and deletion of workgroups under a memory pool is a special case.
In the general case, we are already paying the price of not deleting the metrics for workgroups. Compare my implementation with _update_metrics_unlocked() method in work_group.cpp:
starrocks/be/src/exec/workgroup/work_group.cpp
Lines 475 to 490 in cd9ba32
Your concern of garbage metrics being accumulated applies here even more. I believe the reason it was implemented this way is that deleting metrics entries make handling race conditions more complicated and error-prone.
I can change my implementation so that unused metrics are deleted instead of being set to 0. However, I am not sure if it is worth the extra effort as work_group.cpp does not delete its own metrics anyway.
Let me know which one you prefer.
There was a problem hiding this comment.
ok. will see if other reviewers have some thought. I am ok to keep as is for now.
🌎 Translation Required?✅ All translation files are up to date.
|
511ea62 to
3671e20
Compare
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
3671e20 to
3be1477
Compare
|
I rebased onto the latest main. |
Signed-off-by: arin-mirza <a.mirza@celonis.com>
Signed-off-by: arin-mirza <a.mirza@celonis.com>
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]❌ fail : 41 / 68 (60.29%) file detail
|
Why I'm doing:
There are currently no backend metrics reporting for memory pools.
I previously tried to add them by extending the workgroup metrics, but this turned out to be an incorrect approach:
What I'm doing:
This PR implements metric reporting for
MemTrackerManagerand adds the following new metrics:The implementation follows the same locking structure that is present in
WorkGroupManager.MemTrackerManagerbecause the update_metrics callback hook passed toMetricRegistryneeds to be a closure which captures a write lock.WorkGroupManager.Minor: Changed
list_mem_trackers()method to not return the default memory pool name.Tests and Docs
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: